package com.gxa.zhonglong.service.impl;


import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.StoneCutMapper;
import com.gxa.zhonglong.pojo.StoneClarity;
import com.gxa.zhonglong.pojo.StoneCut;
import com.gxa.zhonglong.service.StoneCutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("stoneCutService")
@Transactional(rollbackFor = {Throwable.class})
public class StoneCutServiceImpl implements StoneCutService {

    @Autowired
    private StoneCutMapper stoneCutMapper;



    @Override
    public Boolean addStoneCut(StoneCut stoneCut) throws BusinessException {
        StoneCut stoneCut1 = stoneCutMapper.selectStoneCutByCode(stoneCut.getCutCode());
        if (stoneCut1 == null) {
            stoneCutMapper.addStoneCut(stoneCut);
            return true;
        }
        throw  new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteStoneCut(List<Long> ids) throws BusinessException {
        if(stoneCutMapper.deleteStoneCut(ids)<1){
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }

    @Override
    public Boolean updateStoneCut(StoneCut stoneCut) throws BusinessException {
        Boolean aBoolean = stoneCutMapper.updateStoneCut(stoneCut);
        if (aBoolean) {
            return true;
        }
        throw new BusinessException(ExceptionCode.DELETE_DEFEATED);
    }

    @Override
    public List<StoneClarity> getStoneCutList() {
        List<StoneClarity> stoneClarities = stoneCutMapper.selectStoneCut();
        return stoneClarities;
    }
}
